/*
* Copyright 2008 Google Inc.
* Licensed under the Apache License, Version 2.0:
*  http://www.apache.org/licenses/LICENSE-2.0
* Modified by Sowmya Balasubramanian and David Robertson
*/
package net.es.weathermap {

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import mx.core.BitmapAsset;

/***
 * InfoWindowSprite is a sprite that contains sub sprites that function as tabs.
 */
public class CustomIconSprite extends Sprite {
    [Embed('markers/routerIcon.png')] private var RouterImg:Class;
    [Embed('markers/hubIcon.png')] private var HubImg:Class;
    [Embed('markers/siteIcon.png')] private var SiteImg:Class;
    [Embed('markers/siteAggr.png')] private var SiteAggrImg:Class;
    [Embed('markers/peerIcon.png')] private var PeerImg:Class;
    [Embed('markers/peerAggr.png')] private var PeerAggrImg:Class;
    [Embed('markers/routerSiteAggr.png')] private var RouterSiteImg:Class;
    [Embed('markers/esnetLogo.png')] private var LogoImg:Class;
    [Embed('markers/whitebg.jpg')] private var BackgroundImg:Class;

    private var offset:Number;

    public function CustomIconSprite(label:String,type:String) {
        var labelMc:TextField = new TextField();
        var labelFormat:TextFormat = new TextFormat("Arial", 12);
        labelFormat.bold = true;
        labelMc.autoSize = TextFieldAutoSize.CENTER;
        labelMc.selectable = false;
        labelMc.background = false;
        labelMc.border = false;
        labelMc.embedFonts = false;
        labelMc.mouseEnabled = false;
        labelMc.text = label;
        labelMc.setTextFormat(labelFormat, -1, -1);
        offset = labelMc.width / 3;
  
        if (type =="logo") {
            labelMc.x = 0;
            labelMc.y = 90;
            var imgObj:BitmapAsset = new LogoImg() as BitmapAsset;
            imgObj.width=60;
            imgObj.height = 50;
            imgObj.x=27;
            imgObj.y=40;
            addChild(imgObj);
        } else {
            if (type != "whitebg") {
                if (type=="hub") {
                    addChild(new HubImg());
                } else if (type=="router") {
                    addChild(new RouterImg());
                } else if (type=="site") {
                    addChild(new SiteImg());
                } else if (type=="siteAggr") {
                    addChild(new SiteAggrImg());
                } else if (type=="peer") {
                    addChild(new PeerImg());
                } else if (type=="peerAggr") {
                    addChild(new PeerAggrImg());
                } else if (type=="siteRouterAggr") {
                    addChild(new RouterSiteImg());
                }
                // label's background image
                if (label != "") {
                    var bgObj:BitmapAsset = new BackgroundImg() as BitmapAsset;
                    bgObj.height = labelMc.height-6;
                    bgObj.width = labelMc.width;
                    bgObj.x=0
                    bgObj.y=-8;
                    addChild(bgObj);
                }
            } else {
                // large background image
                var largeBgObj:BitmapAsset = new BackgroundImg() as BitmapAsset;
                largeBgObj.height = 1200;
                largeBgObj.x=0;
                largeBgObj.y=-300;
                addChild(largeBgObj);
            }
            labelMc.x = 0;
            labelMc.y = -11;
        }
        addChild(labelMc);
        cacheAsBitmap = true;
    }

    public function getOffset():Number {
        return offset;
    }
}
}
